package com.itheima.controller.store;

import com.github.pagehelper.PageInfo;
import com.itheima.controller.BaseServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/store/examineLog")
public class QuestionItemServlet extends BaseServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }


    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 1.获取参数

        String operation = request.getParameter("operation");
        if("list".equals(operation)){
            this.list(request,response);
        }else if("toAdd".equals(operation)){
            this.toAdd(request,response);
        }else if("save".equals(operation)){
            this.save(request, response);
        }else if("toEdit".equals(operation)){
            this.toEdit(request,response);
        }else if("edit".equals(operation)){
            this.edit(request,response);
        }else if("delete".equals(operation)){
            this.delete(request,response);
        }
    }

    private void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         //获取参数
        String pageNum = request.getParameter("page");
        //调用服务层
        PageInfo pageInfo = questionItemService.findByPage(pageNum);
        //响应数据
        request.setAttribute("page",pageInfo);
        //跳转到list页面
        //request.getRequestDispatcher(request.getContextPath()+"/store/examineLog?operation=list").forward(request,response);
        request.getRequestDispatcher(request.getContextPath()+"/WEB-INF/pages/store/questionItem/list.jsp").forward(request,response);
    }



    private void delete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        // 获取参数
//        String id = request.getParameter("id");
//        // 调用服务层
//        questionItemService.delete(id);
//        // 返回查询
//        list(request, response);
        //request.getRequestDispatcher(request.getContextPath()+"/WEB-INF/pages/store/questionItem/list.jsp").forward(request,response);
    }

    private void edit(HttpServletRequest request, HttpServletResponse response) {
    }

    private void toEdit(HttpServletRequest request, HttpServletResponse response) {
    }

    private void save(HttpServletRequest request, HttpServletResponse response) {
    }

    private void toAdd(HttpServletRequest request, HttpServletResponse response) {
    }


}